/**
 * @author jMz
 * @date 2021/9/18 0018
 */
package com.shizhan.first.service;

import com.github.pagehelper.PageHelper;
import com.shizhan.first.entity.Student;
import com.shizhan.first.mapper.StudentMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Slf4j
@Service
public class StudentService {

    @Autowired
    private StudentMapper studentMapper;

//    public List<Student> getStudent() {
//        PageHelper.startPage(1,2);
//        return this.studentMapper.selectAll();
//    }

    public int insertStudent(Student student) {
        return studentMapper.insert(student);
    }

    public Student queryById(Long id) {
        return this.studentMapper.selectByPrimaryKey(id);
    }

    public List<Student> queryStudentAll() {
        PageHelper.startPage(1, 9);
        return this.studentMapper.selectAll();
    }

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public int deleteById(Long id) {
        int iRtn = this.studentMapper.deleteByPrimaryKey(id);
        log.info("iRtn={}", iRtn);
        return iRtn;
    }


    public List<Student> getStudent(){
        return this.studentMapper.getStudent();
    }

}
